<template>
	<view>
		<page-head :title="'产品审批'" :headtype="2"></page-head>
		<view class="nav marginAuto">
			<view class="naveach" @click="navfun(1)" :class="navac == 1 ? 'navactive':''">待审批
				<view class="naveachx"></view>
			</view>
			<view class="naveach" @click="navfun(2)" :class="navac == 2 ? 'navactive':''">已通过
				<view class="naveachx"></view>
			</view>
			<view class="naveach" @click="navfun(3)" :class="navac == 3 ? 'navactive':''">已拒绝
				<view class="naveachx"></view>
			</view>
		</view>
		<view class="allselect marginAuto flex" v-if="navac == 1" @click="allsesqfun">全选</view>
		<view class="sqlist">
			<view class="sqitem marginAuto" v-for="(item,index) in datas" :key="index">
				<view class="sqitemt flex" @click="acgoodsfun(item,index)">
					<view class="sqitemtl flex">
						<view class="sqitemtlicon" style="margin-top:2rpx;" v-if="navac == 1">
							<uv-icon name="checkmark-circle-fill" :color="item.isagreement ? '#2340FF':'#ECECEC'" size="20"></uv-icon>
						</view>
						<view class="sqitemtltitle">{{ item.detail.goods_name}}</view>
					</view>
					<view class="sqitemtstatus">
						<text style="color:#E51818;" v-if="navac == 1">待审批</text>
						<text style="color:#40C40C;" v-if="navac == 2">已通过</text>
						<text style="color:#E51818;" v-if="navac == 3">已拒绝</text>
					</view>
				</view>
				<view class="sqitemc flex" @click="apifun.navigate('/pages/assessor/productsqxq','id='+item.id)">
					<view class="endtimeimg">
						<image v-if="!item.detail.goods_image" :src="apifun.serveimg + 'homegoods.png'" mode=""></image>
						<image v-if="item.detail.goods_image" :src="apifun.URLimg+item.detail.goods_image" mode=""></image>
					</view>
					<view class="endtimemsg">
						<view class="endtimemsg-title">预售数量(吨): <text style="font-weight:600;">{{ item.num }}</text></view>
						<view class="endtimemsg-convert">
							<view class="converteach" v-for="(items,indexs) in item.detail.goods_sku_detail">{{ items.min }}吨-{{ items.max }}吨以内{{ items.price }}元</view>
						</view>
					</view>
				</view>
				<view class="sqitemb">提交时间：{{ item.create_time }}</view>
			</view>
		</view>
		<view class="marginAuto" style="width:600rpx;margin-top:40rpx;" v-if='navac == 1'>
			<uv-button text="审批" @click="sqenterfun()" :customStyle="{
				'background':'#2340FF',
				'color':'#fff',
				'font-size':'30rpx',
				'width':'600rpx',
				'height':'100rpx',
				'border-radius':'20rpx'
			}"></uv-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				apifun:this.apifun,
				page:1,
				navac:1,
				datas:[]
			};
		},
		onLoad(option) {
			this.navac = option.index*1 || 1;
		},
		onShow() {
			this.page = 1;
			this.datas = [];
			this.initData();
		},
		methods: {
			initData(){
				let sendData = {
					page:this.page,
					limit:10,
					status:this.navac+1
				}
				this.apifun.unirequest('/auditor/index/getOrderAuditList','post',sendData,(res)=>{
					if(res.code === 200){
						let datas = res.data;
						if(datas.data.length <= 0){
							this.page--;
							return false
						}
						this.datas.push(...datas.data);
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			sqenterfun(){  // 审批
				let ids = [];
				this.datas.forEach((item,index)=>{
					if(item.isagreement){
						ids.push(item.id)
					}
				});
				let sendData = {
					ids:ids.toString(),
					status:1
				};
				if(ids.length <= 0){
					this.apifun.toast('请选择您要审核的订单')
					return false;
				};
				this.apifun.unirequest('/auditor/index/orderAudit','post',sendData,(res)=>{
					// console.log(res)
					if(res.code === 200){
						let datas = res.data;
						this.page = 1;
						this.datas = [];
						this.initData();
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			acgoodsfun(item,index){
				if(item.isagreement){
					item.isagreement = false;
				}else{
					this.$set(item,'isagreement',true)
				}
			},
			allsesqfun(){
				this.datas.forEach((item,index)=>{
					this.$set(item,'isagreement',true)
				})
			},
			navfun(type){
				this.navac = type;
				this.page = 1;
				this.datas = [];
				this.initData();
			}
		},
		onPullDownRefresh() {
			this.page = 1;
			this.datas = [];
			this.initData();
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			this.page++;
			this.initData()
		},
	};
</script>

<style scoped lang="scss">
	page{
		background: #FBFBFB;
		padding-bottom: 50rpx;
	}
	.nav {
		position:sticky;
		top: 0;
		width:70%;
		padding: 22rpx 5% 40rpx;
		display: flex;
		justify-content: space-between;
		background-color: #fff;
		.naveach {
			position: relative;
			color: #999999;
			font-size:30rpx;
			text-align: center;
	
			.naveachx {
				position: absolute;
				bottom: -10rpx;
				left: 50%;
				background: #fff;
				width: 50rpx;
				margin-left: -25rpx;
				height: 6rpx;
				border-radius: 100rpx;
				transition: background .3s;
			}
		}
	
		.navactive {
			color:#2340FF;
	
			.naveachx {
				background: #2340FF;
			}
		}
	}
	.allselect{
		position:sticky;
		top: 0;
		width: 90%;
		padding:10rpx 5%;
		font-size: 34rpx;
		color: #333333;
		font-weight: 600;
		justify-content: flex-end;
	}
	// list
	.sqlist{
		.sqitem{
			width: 630rpx;
			padding: 0 30rpx;
			background:#fff;
			border-radius:10rpx;
			margin-bottom: 20rpx;
			.sqitemt{
				padding: 20rpx 0;
				border-bottom:1px dashed #F1F1F1;
				justify-content: space-between;
				.sqitemtl{
					.sqitemtltitle{
						font-size: 30rpx;
						color: #333333;
						margin-left:10rpx;
					}
				}
				.sqitemtstatus{
					line-height: 44rpx;
					font-size: 24rpx;
				}
			}
			.sqitemc{
				padding:20rpx 0;
				.endtimeimg{
					width: 140rpx;
					margin-right: 20rpx;
					image{
						width: 140rpx;
						height: 140rpx;
						border-radius: 10rpx;
					}
				}
				.endtimemsg{
					.endtimemsg-title{
						margin-top: 20rpx;
						color:#333333;
						font-size: 30rpx;
					}
					.endtimemsg-convert{
						margin-top: 20rpx;
						.converteach{
							display: inline-block;
							margin-bottom:10rpx;
							margin-right: 10rpx;
							background:#F4F8FC;
							line-height: 52rpx;
							padding:0 10rpx;
							font-size:24rpx;
							color: #2340FF;
							margin-right: 20rpx;
						}
					}
				}
			}
			.sqitemb{
				border-top:1px dashed #F1F1F1;
				font-size:24rpx;
				color: #999;
				line-height:80rpx;
			}
		}
	}
	
</style>